let app = getApp();
var siteinfo = require('../../siteinfo.js');
Page({

  data: {
    if_checked:'',
	pop:false
  },

  onLoad: function (options) {
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    if (prevPage.route == "pages/proAdd/proAdd" || prevPage.route == "pages/signInformation/signInformation") {
      app.globalData.btn = true
    } else {
      app.globalData.btn = false
    }
  },

  onShow: function () {
	  // let _this = this
	  // 	wx.getPrivacySetting({
	  // 		success: res => {
	  // 	console.log("是否需要授权：",res, res.needAuthorization, "隐私协议的名称为：", res.privacyContractName)
	  // //如果需要授权的话 显示弹窗
	  // 			  if(res.needAuthorization){
	  // 				_this.setData({
	  // 				  pop: true
	  // 				});
	  // 			  }
	  			  
	  // 			},
	  // 			fail: () => {},
	  // 			complete: () => {},
	  // 		  })
  },
  handleDisagree(e) {
  					 wx.showToast({ title: '需要同意后，才能继续使用小程序', icon: 'none' });
  				  },
  handleAgreePrivacyAuthorization(res) {
  	  // 用户同意隐私协议事件回调
  	  // 用户点击了同意，之后所有已声明过的隐私接口和组件都可以调用了
  	  //this.$refs.popup.close()
  	 this.setData({
  	   pop: false
  	 });
  	  console.log(res,"handleAgreePrivacyAuthorization");
  	},
  handleOpenPrivacyContract(){
  	// 打开隐私协议页面
  	wx.openPrivacyContract({
  	  success: () => {}, // 打开成功
  	  fail: () => {}, // 打开失败
  	  complete: (res) => {
  		  console.log(res,"openPrivacyContract complete");
  	  }
  	})
    },
  //获取微信绑定的手机号
  getPhoneNumber: function (e) {
    var _this = this
    var code = wx.getStorageSync('code');
    // console.log("code", code)
      // 记录token user_id
    // 发送用户信息
    app._post_form(siteinfo.phoneLoginUrl, {
      code: code,
      encryptedData: e.detail.encryptedData,
      iv: e.detail.iv,
      wxId: siteinfo.wxId
    }, function (result) {
      // 记录token
      //是否含有openId
      wx.setStorageSync('isOpenId', result.data.isOpenId);
      wx.setStorageSync('token', result.data.token);
      wx.setStorageSync('userName', result.data.userName);
      wx.setStorageSync('headPortrait', result.data.headPortrait);
      app._getLogin(siteinfo.unreadNumApi, { type: 0 }, function (result) {
        var unreadNum = result.data
          wx.setStorageSync('unreadNum', unreadNum);
      });
      // 跳转回原页面
       _this.navigateBack();
    }, function (result) {
    }, function () {
      // wx.hideLoading();
    });
  },
  //其他登录方式
  otherLogin: function () {
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  checkboxChange(e){
    var flag = e.detail.value[0];
    if (flag === undefined) {
      this.data.next_class = '';
      flag = false;
    } else {
      this.data.next_class = "text_blue";
      flag = true;
    }
    this.setData({
      if_checked: flag,
      next_class: this.data.next_class
    })
        },
showModal1:function(){
   wx.navigateTo({
          url: '/pages/useRagreement/useRagreement'
        })    
},
  /**
* 跳转回原页面
*/
  navigateBack: function () {
    wx.navigateBack();
  },
})